# from rest_framework.response import Response
# from rest_framework import status
#
#
# class BaseResponse(Response):
#     def __init__(self, data=None, status=None, message=None, code=None, **kwargs):
#         response_data = {}
#         if data is not None:
#             response_data['data'] = data
#         if message is not None:
#             response_data['message'] = message
#         if code is not None:
#             response_data['code'] = code
#
#         super().__init__(data=response_data, status=status, **kwargs)
#
#     @classmethod
#     def success(cls, data=None, message=None):
#         return cls(data=data, status=status.HTTP_200_OK, message=message)
#
#     @classmethod
#     def created(cls, data=None, message=None):
#         return cls(data=data, status=status.HTTP_201_CREATED, message=message)
#
#     @classmethod
#     def bad_request(cls, data=None, message=None):
#         return cls(data=data, status=status.HTTP_400_BAD_REQUEST, message=message)
#
#     @classmethod
#     def unauthorized(cls, data=None, message=None):
#         return cls(data=data, status=status.HTTP_401_UNAUTHORIZED, message=message)
#
#     @classmethod
#     def forbidden(cls, data=None, message=None):
#         return cls(data=data, status=status.HTTP_403_FORBIDDEN, message=message)
#
#     @classmethod
#     def not_found(cls, data=None, message=None):
#         return cls(data=data, status=status.HTTP_404_NOT_FOUND, message=message)
#
#     @classmethod
#     def method_not_allowed(cls, data=None, message=None):
#         return cls(data=data, status=status.HTTP_405_METHOD_NOT_ALLOWED, message=message)
#
#     @classmethod
#     def conflict(cls, data=None, message=None):
#         return cls(data=data, status=status.HTTP_409_CONFLICT, message=message)
#
#     @classmethod
#     def server_error(cls, data=None, message=None):
#         return cls(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR, message=message)

from rest_framework import status as s
from rest_framework.response import Response


class BaseResponse(Response):

    def __init__(self, data=None, status=None, template_name=None, headers=None, exception=False,
                 content_type=None):
        super().__init__(data, status, template_name, headers, exception, content_type)
        self.data = {
            'status': self.status_code,
            'msg': "null",
            'data': self.data
        }

    def success(self, message="success"):
        self.data["msg"] = message
        if self.status_code is None:
            self.data["status"] = s.HTTP_200_OK
        return self

    def fail(self, message="fail"):
        self.data["msg"] = message
        if self.status_code is None:
            self.data["status"] = s.HTTP_400_BAD_REQUEST
        return self
